/**
 * Created by Administrator on 2017/3/14.
 */
var Progress = require('../../../src/libs/progress');
var Pagination = require('../../../src/libs/pagination');
var RealName = require('../../src/complex/realName');
var AccountMes = require('../complex/accountMes');
var FinanceRecord = require('../complex/financeRecord');
var Root = React.createClass({
    getInitialState: function () {
      return{
          realName:PageDM.realNameInfo.value,
          investRecord: PageDM.investRecord.value,
          accountInvest: PageDM.accountInvest.value,
          pageVal: PageDM.pagination.value
      }
    },
    componentDidMount: function(){

        var _this = this;
        UEventHub.on(PageDM.investRecord.dmbind + UI_EVENT_CONST.SET_UDM_VALUE_EVENT, function(v){
            _this.updateInvestRecordHandler(v);
        });
        UEventHub.on(PageDM.accountInvest.dmbind + UI_EVENT_CONST.SET_UDM_VALUE_EVENT, function(v){
            var val = v;
            _this.updateAccountInvestHandler(val);
        });
        //个人实名信息
        UEventHub.on(PageDM.realNameInfo.dmbind + UI_EVENT_CONST.SET_UDM_VALUE_EVENT, function(v){
            _this.updateRealNameInfoHandler(v);
        });
        PageDM.pagination.setValue(PageDM.pagination.value);

        UEventHub.emit("pageLoad","hello world!");
    },
    searchChange: function (e) {

    },
    updateRealNameInfoHandler: function (v) {
        this.setState({
            realName: v
        })
    },
    updateAccountInvestHandler: function (v) {
        this.setState({
            accountInvest: v
        })
    },
    pageClick:function (v) {
        PageDM.pagination.setValue({curPage:v});
        PageDM.pagination.onClick(v);
    },
    updateInvestRecordHandler: function (v) {
        this.setState({
            investRecord:v
        })
    },
    render: function () {
        var _this = this;
        var PageDM = window.PageDM;
        var investRecordDom = [];
        if(this.state.investRecord.list.length > 0){
            investRecordDom.push(<FinanceRecord data={this.state.investRecord.list} />)
        }else {
            if(this.state.investRecord.noPrecedent == -1){
                investRecordDom.push('')
            }else{
                investRecordDom.push(
                    <div className="nodata">
                        <i className="bg-2"></i>暂无待还项目
                    </div>
                );
            }

        }
        return (
            <div>
                <div className="mod-account container">
                    <div className="sub-nav" ref="realName">
                        <RealName data={this.state.realName}/>
                    </div>
                    <div className="account my-account">
                        <div className="count" ref="accountInvest">
                            <AccountMes {...this.state.accountInvest}/>
                        </div>
                        <div className="investment-record financing ">
                            <div className="title"><b></b>最近待还项目<b></b></div>
                            <div  ref="investRecord">{investRecordDom}</div>
                        </div>
                    </div>
                    <div className="clear"></div>
                </div>
                {/*<Pagination  pageVal={_this.state.pageVal} onClick={this.pageClick}></Pagination>*/}

            </div>
        )
    }
});
ReactDOM.render(<Root/>, document.getElementById('giraffe'));